package megrez.boot.autoconfigure.aliyun;

import org.springframework.beans.factory.ObjectProvider;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import com.aliyun.teaopenapi.models.Config;

import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;

/**
 * 自动撇脂
 *  
 * @author Lucky Yang
 * @since 2.6.9
 */
@Slf4j
@RequiredArgsConstructor
@Configuration(proxyBeanMethods = false)
@ConditionalOnClass(Config.class)
@EnableConfigurationProperties({ConfigProperties.class})
public class ConfigAutoConfig {
    @Bean
    public Config config(ConfigProperties properties, ObjectProvider<ConfigConfigurer> configurers) {
        log.info("Initializing aliyun config [{}]", properties);
        
        final Config config = properties.convert(new Config());
        // 自定义配置处理
        configurers.forEach(configurer -> configurer.configure(config));
        return  config;
    }

}
